#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    connect(ui->rbtBlue,SIGNAL(clicked()),this,SLOT(setTextFontColor()));
    connect(ui->rbtBlue,SIGNAL(clicked()),this,SLOT(setTextFontColor()));
    connect(ui->rbtRed,SIGNAL(clicked()),this,SLOT(setTextFontColor()));
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_Underline_checkBox_clicked(bool checked)
{
    QFont font = ui->plainTextEdit->font(); //获得uI界面plainTextEdit中的字
    font.setUnderline(checked); //在字体下面添加横线
    ui->plainTextEdit->setFont(font); //让字体在UI界面plainTextEdit中显示
}

void MainWindow::on_Italic_checkBox_clicked(bool checked)
{
    QFont font=ui->plainTextEdit->font();//获得UI界面plainTextEdit中的字
    font.setItalic(checked); //字体变为斜体
    ui->plainTextEdit->setFont (font); //让字体在U1界面plainTextEdit中显示
}


void MainWindow::on_Bold_checkBox_clicked(bool checked)
{
    QFont font=ui->plainTextEdit->font();//获得UI界面plainTextEdit中的字
    font.setBold(checked); //字体变为斜体
    ui->plainTextEdit->setFont (font); //让字体在U1界面plainTextEdit中显示
}

void MainWindow::setTextFontColor()
{
    QPalette pale = ui->plainTextEdit->palette();

    if(ui->rbtBlack->isChecked())
    {
        pale.setColor(QPalette::Text, Qt::black);
    }
    else if(ui->rbtBlue->isChecked())
    {
        pale.setColor(QPalette::Text, Qt::blue);
    }
    else if(ui->rbtRed->isChecked())
    {
        pale.setColor(QPalette::Text, Qt::red);
    }
    else
    {
        pale.setColor(QPalette::Text, Qt::black);
    }

    ui->plainTextEdit->setPalette(pale);
}

void MainWindow::on_pushButton_3_clicked()
{
    close();
}
